Page({
  data: {
    order: null,
    showCancelDialog: false
  },
  onLoad(options) {
    const { id } = options;
    const orders = wx.getStorageSync('orders') || [];
    const order = orders.find(o => String(o.id) === String(id));
    if (order) {
      this.setData({ order });
    } else {
      wx.showToast({ title: '订单不存在', icon: 'none' });
    }
  },
  onCopyOrderId(e) {
    wx.setClipboardData({
      data: String(e.currentTarget.dataset.id),
      success: () => {
        wx.showToast({ title: '已复制', icon: 'none' });
      }
    });
  },
  onShowCancelDialog() {
    this.setData({ showCancelDialog: true });
  },
  onCancelOrderCancel() {
    this.setData({ showCancelDialog: false });
  },
  onCancelOrderConfirm() {
    const orderId = this.data.order.id;
    let orders = wx.getStorageSync('orders') || [];
    orders = orders.filter(o => String(o.id) !== String(orderId));
    wx.setStorageSync('orders', orders);
    wx.showToast({ title: '订单已取消', icon: 'none' });
    this.setData({ showCancelDialog: false });
    setTimeout(() => {
      wx.navigateBack({ delta: 1 });
    }, 800);
  },
  onPayOrder() {
    wx.showToast({ title: '模拟支付成功', icon: 'success' });
  },
  goBackToOrder() {
    wx.navigateBack({ delta: 1 });
  }
}); 